﻿
@{
    ViewBag.Title = "装车检管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var loadStatuses = ViewBag.LoadStatusEnums as List<KeyValuePair<int, string>>;
}

@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">发货单号：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="txtDeliveryNo" placeholder="请输入发货单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">创建日期：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="txtRangeDate" value="@(DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd")+" 至 "+DateTime.Today.ToString("yyyy-MM-dd"))" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">装车状态：</label>
                    <div class="layui-input-inline">
                        <select id="selStatus" lay-filter="selStatus">
                            <option value="">全部状态</option>
                            @foreach (var item in loadStatuses)
                            {
                                <option value="@item.Key">@item.Value</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-body">
            <table id="table" lay-filter="table"></table>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        initLayui();
        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#txtRangeDate'
                    , range: '至'
                });
                var options = {
                    elem: '#table'
                    , url: '/Warehouse/QueryLoadInspects'
                    , method: "post"
                    , where: { deliveryNo: "", status: null, startDate: "@DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd")", endDate: "@DateTime.Today.ToString("yyyy-MM-dd")" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', width: 60, type: "numbers" }
                        , { field: 'DeliveryNo', title: '发货单号' }
                        , { field: 'CabinetNo', title: '柜号' }
                        , { field: 'LoadedQuantity', title: '已装车箱数' }
                        , { field: 'Quantity', title: '总箱数' }
                        , { field: 'CNLoadBy', title: '装车人' }
                        , { field: 'FinishTimeStr', title: '装车时间' }
                        , { field: 'CNStatus', title: '装车状态' }
                        , {
                            title: '操作', templet: function (d) {
                                var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="loadDetail(' + d.PkId + ')"><i class="layui-icon">&#xe615;</i>装车明细</button>';
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.deliveryNo = $("#txtDeliveryNo").val();
                    options.where.status = $("#selStatus").val().trim() == "" ? null : parseInt($("#selStatus").val().trim());
                    var rangeTime = $("#txtRangeDate").val().trim() == '' ? new Array() : $("#txtRangeDate").val().trim().split(' 至 ');
                    options.where.startDate = rangeTime.length <= 0 ? null : rangeTime[0];
                    options.where.endDate = rangeTime.length <= 0 ? null : rangeTime[1];

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function loadDetail(loadId) {
            parent.layui.index.openTabsPage("/Warehouse/LoadInspectDetail?loadId=" + loadId, "装车详情");
        }
    </script>
}
